﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using iTeachSoft.CoreObjects;
using System.Windows;
using iTeachSoft.Code.Managers;
using iTeachSoft.Presentation.Code.Managers;

namespace iTeachSoft.Presentation.Code.Wrappers
{
    public class ObjectTreeViewItem : TreeViewItem
    {
        private BaseSlideObject mCoreObject = null;
        private Slide mCoreSlide = null;

        public ObjectTreeViewItem(BaseSlideObject coreObject, Slide coreSlide)
        {
            mCoreObject = coreObject;
            mCoreSlide = coreSlide;

            this.Header = coreObject.Name;
            this.Style = (Style)Application.Current.FindResource("TreeViewItemShapeStyle");

            BuildContextMenu();
        }

        private void BuildContextMenu()
        {
            var menu = new ContextMenu();

            var miProperties = new MenuItem() { Header = "Properties" };
            var miDelete = new MenuItem() { Header = "Delete" };
            
            miProperties.Click += new RoutedEventHandler(miProperties_Click);
            miDelete.Click += new RoutedEventHandler(miDelete_Click);

            menu.Items.Add(miProperties);
            menu.Items.Add(miDelete);

            this.ContextMenu = menu;
        }

        void miDelete_Click(object sender, RoutedEventArgs e)
        {
            ActionsManager.DeleteCoreObject(mCoreSlide, mCoreObject);

            EventsManagement.Instance.OnReflectSlideViewerRequested(this, EventArgs.Empty);
            EventsManagement.Instance.OnReflectTreeViewRequested(this, EventArgs.Empty);
        }

        void miProperties_Click(object sender, RoutedEventArgs e)
        {
            //TODO
        }
    }
}
